package org.despair2D.ui.supportClasses 
{
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.utils.getDefinitionByName;
	
	import org.despair2D.core.ns_despair;
	import org.despair2D.debug.Logger;
	import org.despair2D.ui.ButtonType;
	import org.despair2D.ui.puppet.DisplayObjectContainerPuppet;
	import org.despair2D.utils.getInstance;

	use namespace ns_despair;
	
public class AbstractMovieClipButton extends DisplayObjectContainerButton 
{
	/**
	 * 加入影片剪辑数据
	 * @param	movieClipRef
	 * @param	dataName
	 * @param	type
	 */
	public static function addMovieClipButtonData( source:*, dataName:String, buttonType:int ) : void
	{		
		var prop:MovieClipButtonProp
		var movieClipRef:Class
		
		if (m_movieClipButtonPropList[dataName])
		{
			//Logger.reportWarning('AbstractMovieClipButton', 'addMovieClipButtonData', '存在的数据: ' + dataName)
			return
		}
		
		if (source is String)
		{
			movieClipRef = getDefinitionByName(source) as Class
		}
			
		else if (source is Class)
		{
			movieClipRef = source as Class
		}
			
		else
		{
			Logger.reportError('AbstractMovieClipButton', 'addMovieClipButtonData', 'source类型错误.')
		}
		
		switch(buttonType & 0x00F)
		{
			case ButtonType.BUTTON:
				prop = new MovieClipButtonProp();
				prop.initialize(movieClipRef, false)
				break;
				
			case ButtonType.BUTTON_HAS_INVALID:
				prop = new MovieClipButtonProp();
				prop.initialize(movieClipRef, true)
				break;
				
			case ButtonType.CHECKBOX:
				prop = new MovieClipCheckBoxProp();
				prop.initialize(movieClipRef, false)
				break;
				
			case ButtonType.CHECKBOX_HAS_INVALID:
				prop = new MovieClipCheckBoxProp();
				prop.initialize(movieClipRef, true)
				break;
		}
		
		prop.effectType = buttonType & 0x0F0
		m_movieClipButtonPropList[dataName] = prop
	}
	
	
	public function AbstractMovieClipButton( dataName:String ) 
	{
		super()
		m_prop = m_movieClipButtonPropList[dataName]
		if (!m_prop)
		{
			Logger.reportError(this, 'constructor', '不存在的画像按钮数据.')
		}
		m_movieClip = new (m_prop.movieClipRef)
		m_movieClip.gotoAndStop(1)
		m_container.addChild(m_movieClip)
		
		if (m_prop.hasInvalid)
		{
			this.addInvalidEffectListener(onInvalid)
		}
	}	
	
	
	final public function get movieClip() : MovieClip { return m_movieClip }
	
	
	override ns_despair function dispose() : void
	{
		super.dispose()
		m_movieClip = null
		m_prop = null
	}
	
	
	ns_despair static var m_movieClipButtonPropList:Object = new Object()
	
	
	ns_despair var m_movieClip:MovieClip
	
	ns_despair var m_prop:MovieClipButtonProp
}
}